package com.lmpop.updateHtml.updateHtml;

import com.lmpop.frame.util.FileIO;
import com.lmpop.trade.tb_commpara.Tb_commparaInfo;
import com.lmpop.trade.ti_company.Ti_companyInfo;
import com.lmpop.updateHtml.parseHtml.UpdateHtml;
import com.lmpop.updateHtml.parseXml.Config;
import java.util.Hashtable;
import java.util.List;

public class UpdateCustIndexHtml
{
  public String ecms_path;
  public String web_path;
  public String save_path;
  public Config conf;
  public UpdateHtml updateHtml;
  public UpdateJsp udateJsp;

  public UpdateCustIndexHtml()
  {
    this.conf = new Config();
    this.conf.init();
    this.ecms_path = this.conf.getString("rootpath");
    this.web_path = this.conf.getString("companyTempath");
    this.save_path = this.conf.getString("companySavepath");
    this.updateHtml = new UpdateHtml();
    this.udateJsp = new UpdateJsp();
  }

  public void updateWeb(String cust_id, String index_temp, String save_dir, String default_page, String ch_id)
  {
    FileIO copyfold = new FileIO();
    String filepath = this.ecms_path + this.web_path + cust_id;
    boolean flag = FileIO.ExistFloder(filepath);
    if (!flag) {
      CopyFile(cust_id);
      updateIndexHtml(cust_id, index_temp, save_dir, default_page);
      updateCustPartIndexHtml(cust_id, ch_id, "27");
    }
  }

  public void updateIndexHtml(String cust_id, String index_temp, String save_dir, String default_page)
  {
    Hashtable map = new Hashtable();
    map.put("cust_id", cust_id);
    this.updateHtml.updateWeb(index_temp, save_dir, default_page, map);
  }

  public void updateCustPartIndexHtml(String cust_id, String ch_id, String param_attr)
  {
    Tb_commparaInfo commparaInfo = new Tb_commparaInfo();
    Ti_companyInfo companyInfo = new Ti_companyInfo();
    String short_name = companyInfo.getShortNameByPk(cust_id);
    if (short_name.equals("")) short_name = cust_id;

    Hashtable map = new Hashtable();
    map.put("cust_id", cust_id);

    Hashtable commparamap = new Hashtable();
    commparamap.put("param_attr", param_attr);
    if (!ch_id.equals("")) commparamap.put("para_code2", ch_id);
    List list = commparaInfo.getListByCompany(commparamap);
    if ((list != null) && (list.size() > 0)) {
      Hashtable maps = new Hashtable();
      for (int i = 0; i < list.size(); i++) {
        maps = (Hashtable)list.get(i);

        String para_code2 = ""; String para_code3 = ""; String para_code4 = "";
        String para_code5 = ""; String para_code6 = ""; String remark = "";
        if (maps.get("para_code2") != null) {
          para_code2 = maps.get("para_code2").toString().trim();
        }
        if (maps.get("para_code3") != null) {
          para_code3 = maps.get("para_code3").toString().trim();
        }
        if (maps.get("para_code4") != null) {
          para_code4 = maps.get("para_code4").toString().trim();
        }
        if (maps.get("para_code5") != null) {
          para_code5 = maps.get("para_code5").toString().trim();
        }
        if (maps.get("para_code6") != null) {
          para_code6 = maps.get("para_code6").toString().trim();
        }
        if (maps.get("remark") != null) {
          remark = maps.get("remark").toString().trim();
        }

        if (!para_code3.equals("")) {
          String save_dir = this.save_path + short_name + "/";
          String index_temp = this.web_path + cust_id + "/" + para_code3;
          this.updateHtml.updateWeb(index_temp, save_dir, para_code3, map);
        }
      }
    }
  }

  public void CopyFile(String cust_id)
  {
    FileIO copyfold = new FileIO();
    String filepath = this.ecms_path + this.web_path + cust_id;
    String newmodepath = this.ecms_path + "templets/company/templets/default";
    if (!cust_id.equals("")) {
      copyfold.newFolder(filepath);
      copyfold.copyFolder(newmodepath, filepath + "/");
    }
  }

  public static void main(String[] args)
  {
  }
}